//
//  SimBaseVC.m
//  Test
//
//  Created by LiuXubin on 15/11/12.
//  Copyright © 2015年 sim. All rights reserved.
//

#import "SimBaseVC.h"
#import "SimDefine.h"
#import "UIBarButtonItem+SimAdditions.h"

@interface SimBaseVC ()

@end

@implementation SimBaseVC

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        _bViewAppear = NO;
        _bFirstViewAppear = YES;
    }
    
    return self;
}

- (id)initWithTitle:(NSString *)title {
    if (self = [self initWithNibName:nil bundle:nil]) {
        self.title = title;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationItem.title = @"";
    }
    else{
        self.navigationItem.hidesBackButton = YES;
        self.navigationItem.backBarButtonItem = nil;
    }
    
    if (ABOVE_IOS7) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]){
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    
    if (self.navigationController && self.navigationItem.leftBarButtonItem == nil &&
        [self.navigationController.viewControllers firstObject] != self ) {
        [self addBackItem];
    }
    
    if (self.titleStr.length > 0) {
        self.title = self.titleStr;
    }
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _bViewAppear = YES;
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    _bViewAppear = NO;
    if (_bFirstViewAppear) {
        _bFirstViewAppear = NO;
    }
}

- (void)addBackItem
{
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem backBarBtnItem:self];
}


@end
